﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapARANS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveARANS(DataRow dwData, string ITXDBVERSION = "JLT")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryARANS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            } 
            MapARANS(ref dwLocal, dwData);

            if (!flgExist)
            {
                InserARANS(dwLocal); 
            }
            UpdateARANS(dwLocal);
        }
        public void InserARANS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            //APZMANDANT APZART APZVAR APZANRKRS APZALFDNR APZSTUFE
            OracleCommand or1;

            or1 = OracleDB.CreateCommand();
      
            setResult = Connect2Proxy(or1);
        } 
        public void UpdateARANS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand(); 
            Connect2Proxy(or1);
        }
        public DataSet QueryARANS(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            // APZMANDANT  APZART APZVAR APZANRKRS APZALFDNR APZSTUFE

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ARANS WHERE  ROWNUM<2 ";
                    break;
                case 1:  
                    or1.CommandText = "SELECT * FROM ARANS WHERE  "
                        + "  ARAMANDANT=:ARAMANDANT AND ARAAUFKRS=:ARAAUFKRS AND ARAAUFLFD=:ARAAUFLFD AND ARAAUFPOS=:ARAAUFPOS ";
                    or1.Parameters.Add("ARAMANDANT", OracleType.NVarChar).Value = dwData["ARAMANDANT"].ToString();
                    or1.Parameters.Add("ARAAUFKRS", OracleType.NVarChar).Value = dwData["ARAAUFKRS"].ToString();
                    or1.Parameters.Add("ARAAUFLFD", OracleType.NVarChar).Value = dwData["ARAAUFLFD"].ToString(); 
                    or1.Parameters.Add("ARAAUFPOS", OracleType.NVarChar).Value = dwData["ARAAUFPOS"].ToString(); 
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM ARANS WHERE  "
                        + "  ARAMANDANT=:ARAMANDANT AND ARAAUFKRS=:ARAAUFKRS AND ARAAUFLFD=:ARAAUFLFD";
                    or1.Parameters.Add("ARAMANDANT", OracleType.NVarChar).Value = dwData["ARAMANDANT"].ToString();
                    or1.Parameters.Add("ARAAUFKRS", OracleType.NVarChar).Value = dwData["ARAAUFKRS"].ToString();
                    or1.Parameters.Add("ARAAUFLFD", OracleType.NVarChar).Value = dwData["ARAAUFLFD"].ToString();               
                    break;  
                default:
                    break; 
                        
            } 
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "ARANS";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
    }
}
